<?php
	include_once 'isLogin.php';
	$add_success = null;
	$table_name = "companies_categories";
	if ($_GET['level']!=''&& $_GET['level']!=null) {
	     $level = $_GET['level'];
	     $upid = $_GET['upid'];
	   
	}
	if($_POST['submit']){
		if($level>=1 && $level<3){
	   
			//插入数据库
			$data = array('title'=>$_POST['title'],'level'=>$_POST['level'],'upid'=>$_POST['upid']);
			if($_GET['id']!=false){
				$commonc->update($table_name,$data,"id='".$_GET['id']."'");
				$href = $_basename.'?id='.$_GET['id'];
				$add_success = 2;
			}else{
				$commonc->insert($table_name,$data);
				$href='company_add.php';
				$id = $commonc->insert_id();
				$data = array('sort'=>$id);
				$commonc->update($table_name, $data, "id='".$id."'");
				$add_success = 1;
			}
		}else{
			$data=array('title'=>$_POST['title'],'level_id'=>$_POST['level'],'upid'=>$_POST['upid'],'state'=>'2');
			if($_GET['id']!=false){
				$commonc->update("companies",$data,"id='".$_GET['id']."'");
				$href = $_basename.'?id='.$_GET['id'];
				$add_success = 2;
			}else{
				$commonc->insert("companies",$data);
				$href='company_add.php';
				$id = $commonc->insert_id();
				$data = array('sort'=>$id);
				$commonc->update("companies", $data, "id='".$id."'");
				$add_success = 1;
			}
		}		
		//echo $commonc->submitAlert('成功',$href);
	}
	
	//获得数据
	if($_GET['id']!=false){
		$row=$commonc->getInfo($table_name,$_GET['id']);
		$rowss=$commonc->getInfo('companies',$_GET['id']);
		$smarty->assign('rowss',$rowss);
		$smarty->assign('row',$row);
		$smarty->assign('area',$area);
	}
	$smarty->assign('add_success',$add_success);
	$smarty->assign('level',$level);
	$smarty->assign('upid',$upid);
	$smarty->display($_filename.".html");
	
?>